<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>03-绘制线段</title>
    <style>
      canvas {
        border: 1px solid black;
      }
    </style>
  </head>
  <body>
    <canvas width="600" height="400"></canvas>
    <script>
      // 1. 获取标签对象
      const canvas = document.querySelector('canvas');

      // 2. 创建上下文对象 其实就相当于是获取画笔对象
      const ctx = canvas.getContext('2d');

      // console.log(ctx)

      ctx.moveTo(0, 0);
      ctx.lineTo(50, 0);
      ctx.lineTo(150, 300);
      ctx.lineTo(400, 400);
      ctx.lineTo(400, 200);
      ctx.lineTo(500, 50);
      ctx.strokeStyle = 'red';
      ctx.stroke(); // 表示画
    </script>
  </body>
</html>
